package com.server;

import java.io.IOException;
import java.sql.SQLException;

import java.util.*;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.Helper.*;

public class ViewPassServlet extends CustomerServlet
{
	private static final long serialVersionUID = 1L;
	private final String className = "View Pass Servlet: ";

	@Override
	//@requires HttpServletRequest !=NULL,  HttpServletResponse !=NULL ;
    //@assignable passList,flightlist,username;
    //@ensures 	req.setAttribute("flightID", flightID) && req.setAttribute("username", username) && req.getRequestDispatcher("reservation/reserveFlight.jsp").forward(req, resp);	
	//@signals_only RuntimeException, IOException,ServletException;
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException
	{
		ConnectDB();
		String username = req.getParameter("username");
		ArrayList<PassInfo> passList = new ArrayList<PassInfo>();
		ArrayList<FlightInfo> flightList = new ArrayList<FlightInfo>();
		Boolean isEmpty = null;
		
		try //get the pass info and display them
		{
			ReservationHelper.Setup(connection, username);
			ReservationHelper.UpdateResStatus(username);
			passList = ReservationHelper.GetPassList();
			flightList = ReservationHelper.GetFlightList();
			
			if(flightList.size()==0){
				isEmpty=true;
			}else{
				isEmpty=false;
			}
			req.setAttribute("passList", passList);
			req.setAttribute("flightList", flightList);
			req.setAttribute("isEmpty", isEmpty);
		} 
		catch (SQLException e) 
		{
			e.printStackTrace();
		}
	
		req.setAttribute("username", username);
		req.getRequestDispatcher("reservation/ViewPass.jsp").forward(req, resp);	
	}

}

